package com.mainvnm.QRAndroid2;

import com.google.zxing.integration.android.IntentIntegrator;
import com.google.zxing.integration.android.IntentResult;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class QRAndroid2Activity extends Activity {
    /** Called when the activity is first created. */
	//IntentIntegrator integrator = new IntentIntegrator(yourActivity);
	//integrator.initiateScan();
	Intent intent = new Intent("com.google.zxing.client.android.SCAN");
	TextView statusText = (TextView) findViewById(R.id.textView1);
	
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        
        final Button button = (Button) findViewById(R.id.button1);
        button.setOnClickListener(new OnClickListener()
        {

        	
        	public void onClick(View v)
        	{
                // Perform action on clicks
        		IntentIntegrator integrator = new IntentIntegrator(QRAndroid2Activity.this);
        		integrator.initiateScan();
        	    //integrator.initiateScan(IntentIntegrator.QR_CODE_TYPES);

        		IntentResult scanResult = IntentIntegrator.parseActivityResult(0x0000c0de, -1, intent);
                //IntentResult scanResult = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
                if (scanResult != null) {
                	Toast.makeText(QRAndroid2Activity.this, "Yes", Toast.LENGTH_SHORT).show();
                	scanResult = null;
                }
            }
        });
        
    }
    
    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent intent) {
      IntentResult result = IntentIntegrator.parseActivityResult(requestCode, resultCode, intent);
      if (result != null) {
        String contents = result.getContents();
        if (contents != null) {
          //showDialog(R.string.result_succeeded, "Format: " + result.getFormatName() + "\nContents: " + contents);
        	Toast.makeText(QRAndroid2Activity.this, contents, Toast.LENGTH_SHORT).show(); //NOTE: "contents" is the string that is contained in the QR code
        	////Toast.makeText is only there for example, the contents string can be passed into other methods
        } else {
          //showDialog(R.string.result_failed, getString(R.string.result_failed_why));
        }
      }
    }

    
}